﻿using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace HalconDotNet
{
	// Token: 0x0200009A RID: 154
	internal class HTupleDouble : HTupleImplementation
	{
		// Token: 0x06001F93 RID: 8083 RVA: 0x000B9F31 File Offset: 0x000B8131
		protected override Array CreateArray(int size)
		{
			return new double[size];
		}

		// Token: 0x06001F94 RID: 8084 RVA: 0x000B9F39 File Offset: 0x000B8139
		protected override void NotifyArrayUpdate()
		{
			this.d = (double[])this.data;
		}

		// Token: 0x06001F95 RID: 8085 RVA: 0x000B9F4C File Offset: 0x000B814C
		public HTupleDouble(double d)
		{
			base.SetArray(new double[]
			{
				d
			}, false);
		}

		// Token: 0x06001F96 RID: 8086 RVA: 0x000B9AE4 File Offset: 0x000B7CE4
		public HTupleDouble(double[] d, bool copy)
		{
			base.SetArray(d, copy);
		}

		// Token: 0x06001F97 RID: 8087 RVA: 0x000B9F65 File Offset: 0x000B8165
		public HTupleDouble(float[] f)
		{
			base.SetArray(f, true);
		}

		// Token: 0x06001F98 RID: 8088 RVA: 0x000B9F75 File Offset: 0x000B8175
		internal override void PinTuple()
		{
			Monitor.Enter(this);
			if (this.pinCount == 0)
			{
				this.pinHandle = GCHandle.Alloc(this.d, GCHandleType.Pinned);
			}
			this.pinCount++;
			Monitor.Exit(this);
		}

		// Token: 0x06001F99 RID: 8089 RVA: 0x000B9FAB File Offset: 0x000B81AB
		public override HTupleElements GetElement(int index, HTuple parent)
		{
			return new HTupleElements(parent, this, index);
		}

		// Token: 0x06001F9A RID: 8090 RVA: 0x000B9FB5 File Offset: 0x000B81B5
		public override HTupleElements GetElements(int[] indices, HTuple parent)
		{
			if (indices == null || indices.Length == 0)
			{
				return new HTupleElements();
			}
			return new HTupleElements(parent, this, indices);
		}

		// Token: 0x06001F9B RID: 8091 RVA: 0x000B9FCC File Offset: 0x000B81CC
		public override void SetElements(int[] indices, HTupleElements elements)
		{
			new HTupleElementsDouble(this, indices).setD(elements.DArr);
		}

		// Token: 0x17000098 RID: 152
		// (get) Token: 0x06001F9C RID: 8092 RVA: 0x000B9FE0 File Offset: 0x000B81E0
		// (set) Token: 0x06001F9D RID: 8093 RVA: 0x000B9B31 File Offset: 0x000B7D31
		public override double[] DArr
		{
			get
			{
				return this.d;
			}
			set
			{
				base.SetArray(value, false);
			}
		}

		// Token: 0x17000099 RID: 153
		// (get) Token: 0x06001F9E RID: 8094 RVA: 0x000B8761 File Offset: 0x000B6961
		public override HTupleType Type
		{
			get
			{
				return HTupleType.DOUBLE;
			}
		}

		// Token: 0x06001F9F RID: 8095 RVA: 0x000B9B61 File Offset: 0x000B7D61
		public override double[] ToDArr()
		{
			return (double[])base.ToArray(this.typeD);
		}

		// Token: 0x06001FA0 RID: 8096 RVA: 0x000B9FE8 File Offset: 0x000B81E8
		public override float[] ToFArr()
		{
			float[] array = new float[this.iLength];
			for (int i = 0; i < this.iLength; i++)
			{
				array[i] = (float)this.d[i];
			}
			return array;
		}

		// Token: 0x06001FA1 RID: 8097 RVA: 0x000BA01F File Offset: 0x000B821F
		public override int CopyToDArr(double[] dst, int offset)
		{
			Array.Copy(this.d, 0, dst, offset, this.iLength);
			return this.iLength;
		}

		// Token: 0x06001FA2 RID: 8098 RVA: 0x000BA03C File Offset: 0x000B823C
		public override int CopyToOArr(object[] dst, int offset)
		{
			for (int i = 0; i < this.iLength; i++)
			{
				dst[i + offset] = this.d[i];
			}
			return this.iLength;
		}

		// Token: 0x06001FA3 RID: 8099 RVA: 0x000BA072 File Offset: 0x000B8272
		public override int CopyFrom(HTupleImplementation impl, int offset)
		{
			return impl.CopyToDArr(this.d, offset);
		}

		// Token: 0x06001FA4 RID: 8100 RVA: 0x000BA084 File Offset: 0x000B8284
		public override void Store(IntPtr proc, int parIndex)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.GetInputTuple(proc, parIndex, out tuple));
			this.StoreData(proc, tuple);
		}

		// Token: 0x06001FA5 RID: 8101 RVA: 0x000BA0A8 File Offset: 0x000B82A8
		protected override void StoreData(IntPtr proc, IntPtr tuple)
		{
			this.PinTuple();
			HalconAPI.SetDArrPtr(tuple, this.d, this.iLength);
		}

		// Token: 0x06001FA6 RID: 8102 RVA: 0x000BA0C4 File Offset: 0x000B82C4
		public static int Load(IntPtr tuple, out HTupleDouble data)
		{
			int num;
			HalconAPI.GetTupleLength(tuple, out num);
			double[] doubleArray = new double[num];
			int darr = HalconAPI.GetDArr(tuple, doubleArray);
			data = new HTupleDouble(doubleArray, false);
			return darr;
		}

		// Token: 0x04001188 RID: 4488
		protected double[] d;
	}
}
